package com.ruoyi.system.dobbo;

import com.ruoyi.common.resp.domain.R;
import com.ruoyi.system.api.dobbo.RemoteLogService;
import com.ruoyi.common.user.domain.SysLogininfor;
import com.ruoyi.common.user.domain.SysOperLog;
import com.ruoyi.system.service.ISysLogininforService;
import com.ruoyi.system.service.ISysOperLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 日志打印能力
 * @author chaoliu
 */
@Service
@DubboService
@Slf4j
public class RemoteLogServiceImpl implements RemoteLogService {

    @Autowired
    private ISysOperLogService operLogService;

    @Autowired
    private ISysLogininforService logininforService;

    @Override
    public R<Boolean> saveLog(SysOperLog sysOperLog, String source) throws Exception {
        int rows =operLogService.insertOperlog(sysOperLog);
        return rows > 0 ? R.ok(true) : R.fail(false);
    }

    /**
     * 插入登录日志
     * @param sysLogininfor 访问实体
     * @param source        请求来源
     * @return
     */
    @Override
    public R<Boolean> saveLogininfor(SysLogininfor sysLogininfor, String source) {
        int rows = logininforService.insertLogininfor(sysLogininfor);
        return rows > 0 ? R.ok(true) : R.fail(false);
    }

}